package com.jwell.panrank.ui.fragment.inquire;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jwell.cargoapp.ui.base.MVPBaseFragment;
import com.jwell.panrank.R;
import com.jwell.panrank.contract.CarInquireContract;
import com.jwell.panrank.entity.CarInquireBean;
import com.jwell.panrank.presenter.CarInquirePresenter;
import com.jwell.panrank.ui.adapter.CarInquireAdapter;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class InquireFragment extends MVPBaseFragment<CarInquirePresenter> implements CarInquireContract.View{
    private List listData =new ArrayList<CarInquireBean>();
    private RecyclerView mRecyclerView;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.activity_car_inquire_layout, container, false);
        mRecyclerView = view.findViewById(R.id.recyclerView);
//        createPresenter().searchListData();
        return view;
    }

    @org.jetbrains.annotations.Nullable
    @Override
    public CarInquirePresenter createPresenter() {

        CarInquirePresenter presenter=   new CarInquirePresenter();
        presenter.searchListData();
        return presenter;
    }

    @Override
    public void showListData(@NotNull List<? extends CarInquireBean> data, boolean isFresh) {
        Log.d("tag","showListData-"+data);
        listData.clear();
        listData.addAll(data);

         CarInquireAdapter adapter = new CarInquireAdapter(listData);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        mRecyclerView.setAdapter(adapter);
    }

    @Override
    public void showListDataFailed(boolean isFresh, @NotNull String str) {

    }
}
